package linuxbox.todo.servlet;

import javax.servlet.http.*;

import linuxbox.*;
import linuxbox.common.*;
import linuxbox.todo.logic.*;

public class BoxTodoSettingsAction
    extends Action
{
  protected static String viewJSP = null;
  protected static String adminJSP = null;
  protected static String editJSP = null;

  public void doAction(HttpSession aSession, BoxSession aBoxSession,
                       HttpServletRequest req, HttpServletResponse resp) throws
      Exception
  {
    String str = req.getParameter("SubmitCancel");
    if (str != null)
    {
      sendFile(viewJSP, req, resp);
      return;
    }

    str = (String) req.getParameter("SubmitSave");
    if (str != null)
    {
      BoxTodoCat.setUserCategories(aBoxSession, req.getParameterValues("CATEGORIES"));
      str = req.getParameter("ENTRIES_PER_PAGE");
      aBoxSession.setConfigInt("todo", "General", "Entries Per Page",
                               Integer.parseInt(str));
      sendFile(viewJSP, req, resp);
      return;
    }

    str = (String) req.getParameter("SubmitSysSave");
    if (str != null)
    {
      if (aBoxSession.isTodoAdmin())
      {
        BoxTodoCat.setSystemCategories(req.getParameterValues("CATEGORIES"));
        sendFile(adminJSP, req, resp);
        return;
      }
      else
      {
        logger.debug(aBoxSession.getLoginID() +
                     " access right error for module: " + "todo");
        sendFile(BoxStatic.accessRightErrorJSP, req, resp);
        return;
      }
    }

    str = (String) req.getParameter("SubmitEdit");
    if (str != null)
    {
      req.setAttribute("SYSTEMCAT", "0");
      int i = aBoxSession.getConfigInt("todo", "General", "Entries Per Page");
      req.setAttribute("ENTRIES_PER_PAGE", Integer.toString(i));
      sendFile(editJSP, req, resp);
      return;
    }

    str = (String) req.getParameter("SubmitSysEdit");
    if (str != null)
    {
      if (aBoxSession.isTodoAdmin())
      {
        req.setAttribute("SYSTEMCAT", "1");
        sendFile(editJSP, req, resp);
        return;
      }
      else
      {
        logger.debug(aBoxSession.getLoginID() +
                     " access right error for module: " + "todo");
        sendFile(BoxStatic.accessRightErrorJSP, req, resp);
        return;
      }
    }
    sendFile(viewJSP, req, resp);
  }

  public void setViewJSP(String str)
  {
    viewJSP = str;
  }

  public void setEditJSP(String str)
  {
    editJSP = str;
  }

  public void setAdminJSP(String str)
  {
    adminJSP = str;
  }
}
